$(document).ready(function(){
    $.fn.dataTable.ext.errMode = 'none';
    $('#table_list').on( 'error.dt', function ( e, settings, techNote, message ) {
        $.jBox.error(GLOBAL_DATATBALE_ERROR_302, '错误');
        return false;
    } ).DataTable({
        dom: '<"top">rt<"bottom"flip><"clear">',
        language: {
            "sUrl":'../static/plugins/datatables/language.json'
        },
        "searching": false,
        "processing": true,
        "serverSide": true,
        ajax:{
            url:'/sys-log/frontend-load-list',
            type:'post',
            data:function(d){
                d.source_type = $('#source_type').val();
                d.user_name = $('#user_name').val();
                d.reservationtime = $('#reservationtime').val();
                d.tracker_code = $('#tracker_code').val();
                d.ip = $('#ip').val();
                d.key1 = $('#key1').val();
                d.key2 = $('#key2').val();
                d.key3 = $('#key3').val();
            },
            error:getError
        },
        aoColumns: [
            { "data": "id", "bSortable": true},
            { "data": "source_type", "bSortable":false },
            { "data": "user_name", "bSortable":false },
            { "data": "create_time", "bSortable":false },
            { "data": "tracker_code", "bSortable":false },
            { "data": "key1", "bSortable":false },
            { "data": "key2", "bSortable":false },
            { "data": "key3", "bSortable":false },
            { "data": "ip", "bSortable":false },
            { "data": "url", "bSortable":false },
        ],
        columnDefs: [
        ],

        order: [[ 0, "desc" ]]
    });
});

$('#reservationtime').daterangepicker({
    language:  'zh-CN',
//    timePicker: true,
//    timePickerIncrement: 30,
    format: 'YYYY/MM/DD',
    locale: {
        format: 'YYYY-MM-DD',
        daysOfWeek: ['日', '一', '二', '三', '四', '五', '六'],
        monthNames: ['一月', '二月', '三月', '四月', '五月', '六月', '七月', '八月', '九月', '十月', '十一月', '十二月'],
    }
});

$('#select_button').click(function(){
    var table = $('#table_list').DataTable();
    table.ajax.reload();
});

$('#reset_button').click(function(){
	var str_date = show();
	$('#source_type').val('');
    $('#user_name').val('');
    $('#reservationtime').val('');
    $('#tracker_code').val('');
    $('#ip').val('');
    $('#key1').val('');
    $('#key2').val('');
    $('#key3').val('');
    var table = $('#table_list').DataTable();
    table.ajax.reload();
});

function show() {
    var date = new Date();
    var seperator1 = "-";
    var month = date.getMonth() + 1;
    var strDate = date.getDate();
    if (month >= 1 && month <= 9) {
        month = "0" + month;
    }
    var currentdate = date.getFullYear() + seperator1 + month + seperator1 + strDate
    return currentdate;
}
